import { reactive, ref } from 'vue'
import { VxeGridProps } from 'vxe-table'

const gridOptions = reactive<VxeGridProps<any>>({
  border: true,
  height: 300,
  align: 'center',
  loading: false,
  columnConfig: {
    resizable: true,
  },
  columns: [
    { field: 'id', title: '记录ID' },
    { field: 'achievementName', title: '成果名称' },
    {
      field: 'completeUnit', title: '完成单位',
      formatter({ row }) {
        try {
          const parsedData = JSON.parse(row.completeUnit || '[]');
          if (Array.isArray(parsedData)) {
            const names = parsedData.map(item => item.name).join('，');
            return names;
          } else {
            return '';
          }
        } catch (error) {
          console.error('Error parsing JSON:', error);
          return '';
        }
      },
    },
    { field: 'reportUnitName', title: '上报单位' },
    { field: 'reportPersonName', title: '上报人' },
    { field: 'createTime', title: '记录创建时间', formatter: ['formatDate', 'yyyy-MM-dd'] },
    { title: '操作', width: 200, slots: { default: 'operate' } },
  ],
  data: [],
})

const valueoptions = reactive([
  {
    label: '课题名称',
    value: 'secretsName',
  },
  {
    label: '课题编号',
    value: 'unit',
  },
  {
    label: '课题负责人',
    value: 'date',
  },
  {
    label: '项目名称',
    value: 'date',
  },
  {
    label: '项目编号',
    value: 'date',
  },
  {
    label: '项目负责人',
    value: 'date',
  },
  {
    label: '预算申请ID',
    value: 'date',
  },
  {
    label: '上报人',
    value: 'date',
  },
])

interface from {
  label: string
  prop: string
  type?: string //select / date /tree
  options?: Array<{ name: string; id: number }>
  isDisabled?: boolean
}

const formList = ref<from[]>([
  {
    label: '完成单位:',
    prop: 'completeUnit',
    type: 'select',
    options: [],
  },
  {
    label: '上报单位:',
    prop: 'reportUnitId',
    type: 'select',
    options: [],
  },
  {
    label: '上报日期:',
    prop: 'reportDate',
    type: 'date',
  },
  {
    label: '成果名称:',
    prop: 'achievementName',
    type: 'input',
  },
])

interface fromItem {
  label: string
  prop: string
  descs?: string
  rules?: Array<{ required: boolean; message: string; trigger: string }>
}

const companyForm = ref<fromItem[]>([
  {
    label: '总封皮及总目录:',
    prop: 'contentsDoc',
    descs: '总目录包含01-11，不包含汇报多媒体、鉴定证书',
    rules: []
  },
  {
    label: '计划任务书:',
    prop: 'planningDoc',
    rules: []
  },
  {
    label: '成果报告:',
    prop: 'achievementReportDoc',
    rules: []
  },
  {
    label: '查新报告:',
    prop: 'searchReportDoc',
    descs: '国家一级科技查新机构出具的一年以内的国内外查新',
    rules: []
  },
  {
    label: '应用证明:',
    prop: 'appProveDoc',
    rules: []
  },
  {
    label: '环保安全报告或变为检测报告:',
    prop: 'envirSecureDoc',
    rules: []
  },
  {
    label: '检测报告:',
    prop: 'detectionReportDoc',
    rules: []
  },
  {
    label: '经济效益社会效益分析报告:',
    prop: 'economicAnalysisDoc',
  },
  {
    label: '产品或者技术标准:',
    prop: 'productStandardDoc',
  },
  {
    label: '知识产权证明:',
    prop: 'propertyIdentifyDoc',
  },
  {
    label: '验收评价报告:',
    prop: 'evaluationDoc',
  },
  {
    label: '其他:',
    prop: 'otherDoc',
  },
  {
    label: '汇报多媒体:',
    prop: 'multimediaReportDoc',
  },
])

const tianjingForm = ref<fromItem[]>([
  {
    label: '一、工作报告:',
    prop: 'aa',
    // descs: '总目录包含01-11，不包含汇报多媒体、鉴定证书',
    rules: [{ required: true, message: '请上传文件', trigger: 'blur' }]
  },
  {
    label: '二、研究报告:',
    prop: 'bb',
    rules: [{ required: true, message: '请上传文件', trigger: 'blur' }]
  },
  {
    label: '三、科技查新报告:',
    prop: 'cc',
    rules: [{ required: true, message: '请上传文件', trigger: 'blur' }],
    descs: '半年有效期',
  },
  {
    label: '四、用户应用证明:',
    prop: 'dd',
    rules: [{ required: true, message: '请上传文件', trigger: 'blur' }],
  },
  {
    label: '五、经济效益分析报告:',
    prop: 'ee',
    rules: [{ required: true, message: '请上传文件', trigger: 'blur' }],
  },
  {
    label: '六、检测报告:',
    prop: 'ff',
    rules: [{ required: true, message: '请上传文件', trigger: 'blur' }],
    descs: '由天津市检测鉴定机构出具或专家测试小组现场测试',
  },
  {
    label: '七、合同或任务下达书:',
    prop: 'ee',
    descs: '由上级主管单位或任务下达单位出具',
  },
  {
    label: '八、质量标准:',
    prop: 'ff',
  },
  {
    label: '九、环保证明:',
    prop: 'gg',
  },
  {
    label: '十、安全证明:',
    prop: 'hh',
  },
  {
    label: '十一、专利发明:',
    prop: 'ii',
    descs: '若有必备',
  },
  {
    label: '十二、行业准入类项目或需行政审批类项目:',
    prop: 'jj',
    descs: '除上述资料外，还应提供相应的许可证或审批手续，医疗器械许可证、已备案的企业标准',
  },
  {
    label: '十三、企业执照:',
    prop: 'kk',
  },
  {
    label: '十四、科技成果鉴定申请表:',
    prop: 'mm',
    descs: '原件一式三份',
  },
])

export { gridOptions, formList, valueoptions, companyForm, tianjingForm }
